local blaze  = require "blaze"
local app = require "app"
local game = require "club.threecard.sudoku"

local M = game.ui.activity()

M.store_watchers = {
}

function M:ctor()
    self.res = "club.threecard.sudoku/ui/main.b:Setting"

    local Toggle = require "club.threecard.sudoku.ui.common.Toggle"
    self.bgm_toggle = Toggle.new(not app.bgm.get_mute())
    self.sfx_toggle = Toggle.new(not app.sfx.get_mute())
    self.vibration_toggle = Toggle.new(app.vibration.on)
end

function M:on_injected(bind)
    bind("sudoku.toggle.value", self.bgm_toggle_obj, self.bgm_toggle, self.on_bgm)
    bind("sudoku.toggle.value", self.sfx_toggle_obj, self.sfx_toggle, self.on_sfx)
    bind("sudoku.toggle.value", self.vibration_toggle_obj, self.vibration_toggle, self.on_vibration)
    bind("button.click", self.policy_btn, self.on_policy)
    bind("button.click", self.logout_btn, self.on_logout)
end

function M:on_set_parent()
    self:super("on_set_parent")
    self.transform:Stretch()
end

function M:on_bgm(on)
    game.audio.post("click")
    local mute = app.bgm.get_mute()
    app.bgm.mute(not mute)
end

function M:on_sfx(on)
    game.audio.post("click")
    local mute = app.sfx.get_mute()
    app.sfx.mute(not mute)
end

function M:on_vibration(on)
    game.audio.post("click")
    app.vibration.set(not app.vibration.on)
end

function M:on_policy()
    game.audio.post("click")
    CS.UnityEngine.Application.OpenURL(app.entry.privacy_policy)
end

function M:on_logout()
    game.audio.post("click")
    app.store.account.logout()
end

return M